package com.xhwl.centiotdata.pollingtrigger.passengerflow;

import com.alibaba.fastjson.JSON;
import com.xhwl.centiotdata.handler.passengerflow.impl.PassengerFlowIntegrationICCHandler;
import com.xhwl.centiotdata.pojo.dto.passengerflow.PassengerFlowIntegrationConfigDTO;
import com.xhwl.centiotdata.pollingtrigger.ScheduleDispatcher;
import com.xhwl.centiotdata.service.integrateconfig.PassengerFlowIntergrationConfig;
import com.xhwl.common.exception.DataException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Falcon.cao @Copyright (C), 2022, 兴海物联
 * Date: 2022/9/15 8:28
 * Description: 包信息
 */
@Component
@Slf4j
public class PassengerFlowDispatcher implements ScheduleDispatcher {

    @Autowired
    private PassengerFlowIntegrationICCHandler passengerFlowIntegrationICCHandler;

    @Autowired
    private PassengerFlowIntergrationConfig integrationConfig;

    @Override
    public void doFiveMinutesTask() {
        Map<Integer, List<PassengerFlowIntegrationConfigDTO>> integerListMap = integrationConfig.getIntegrationConfig();
        log.info("找到相关配置内容:{}" + JSON.toJSONString(integerListMap));
        integerListMap.keySet().forEach(id -> {
            List<PassengerFlowIntegrationConfigDTO> passengerFlowIntegrationConfigDTOList = integrationConfig.getIntegrationConfig(id);
            if (passengerFlowIntegrationConfigDTOList == null || passengerFlowIntegrationConfigDTOList.size() == 0) {
                throw new DataException("未配置数据");
            }
            PassengerFlowIntegrationConfigDTO configDTO = passengerFlowIntegrationConfigDTOList.get(0);
            if (configDTO.getRegionConfigs() == null || configDTO.getRegionConfigs().size() == 0) {
                throw new DataException("未配置数据");
            }
            log.info("配置参数:{}" + JSON.toJSONString(configDTO));
            passengerFlowIntegrationICCHandler.syncStaticFlowData(configDTO);
        });
    }
}
